package com.lyc.day1103.demo02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author ：Xiaochen
 * @date ：Created in 2022/11/3 20:32
 * @description：
 * @modified By：
 * @version:
 */
public class Test03 {
    public static void main(String[] args) {
        List<Student> list=new ArrayList<>();
        list.add(new Student("小诗诗",18));
        list.add(new Student("臣哥哥",17));
        list.add(new Student("大幂幂",16));
        list.add(new Student("林允儿",15));

//        Comparator<Student> comparator=new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getAge()-o2.getAge();
//            }
//        };


        Comparator<Student> comparator=(o1,o2)->{return o1.getAge()-o2.getAge();};
        Collections.sort(list,comparator);
        System.out.println(list);
    }
}
class Student{
    private String name;
    private Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';

    }
}